# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :report_handler.py
# @Time      :2022/3/14 23:29
# @Author    :Yongbo Zhou

# 报文字段定义
import abc
import inspect
import re
from abc import ABCMeta, abstractmethod

from data import db
from tools import Common


#
# # 位置自定义
# class IndexFun(object):
#     __metaclass__ = ABCMeta
#
#     @abstractmethod
#     def index(self, byte_arr: list[str], r_p_dict: dict):
#         pass
#
#
# # 解码自定义
# class DecodeFun(object):
#     __metaclass__ = ABCMeta
#
#     @abstractmethod
#     def decode(self,*args,**kwargs):
#         pass


# 协议字段定义
class ReportField:

    # order_no 排序序号
    # index : 默认起始位置
    # start_index: 字段的开始位置
    # end_index : 字段的结束位置
    # encode_fun : 字段编码
    # decode_ fun : 字段解码
    # start_fun : 字段的开始位置方法 当start_index = None 则必填
    # end_fun : 字段的结束位置方法 当end_index = None 则必填
    # custom_encode_fun : 字段无法确定位置 则为自己实现编码
    # custom_decode_fun : 字段无法确定位置 则为自己实现解码
    def __init__(self, order_no: int, start_index: int = None, end_index: int = None,
                 encode_fun=None, decode_fun=None, start_fun=None, end_fun=None,
                 custom_encode_fun=None, custom_decode_fun=None) -> None:
        self.start_index = start_index
        self.end_index = end_index
        self.encode_fun = encode_fun
        self.decode_fun = decode_fun
        self.order_no = order_no
        self.start_fun = start_fun
        self.end_fun = end_fun
        self.custom_encode_fun = custom_encode_fun
        self.custom_decode_fun = custom_decode_fun
        super().__init__()

    # 解码
    # r_p_dict={}, byte_arr: list[str] = None, decode_obj=None
    def decode(self, *args, **kwargs):
        # 自定义解码
        if self.custom_decode_fun is not None:
            ret = self.custom_decode_fun(*args, **kwargs)
            kwargs['r_p_dict'][kwargs['fieldName']] = ret
            return ret
        offset = kwargs['offset']
        if offset is None:
            offset = 0
        start_index = self.start_index
        end_index = self.end_index
        if start_index is None:
            start_index = self.start_fun(*args, **kwargs)
        else:
            start_index += offset
        if end_index is None:
            end_index = self.end_fun(*args, **kwargs)
        else:
            end_index += offset
        ret = self.decode_fun(args[0][start_index:end_index + 1])
        kwargs['r_p_dict'][kwargs['fieldName']] = start_index, end_index, ret
        return start_index, end_index, ret


# 报文头定义
class RealtimeSignal:
    # 日志字段
    # reportTime = None
    # vin_code = None
    #
    # infoTime = None
    # reportHeXInfo = None

    # 协议字段
    # 标识 0-1
    flag = ReportField(start_index=0, end_index=1, order_no=0, encode_fun=None, decode_fun=Common.hex_ascii)
    # 指令 2
    command = ReportField(start_index=2, end_index=2, order_no=1, encode_fun=None, decode_fun=Common.hex_int)
    # 应答标识  3
    res_flag = ReportField(start_index=3, end_index=3, order_no=2, encode_fun=None, decode_fun=Common.hex_int)
    # 唯一标识符 4-20
    uid = ReportField(start_index=4, end_index=20, order_no=3, encode_fun=None, decode_fun=Common.hex_ascii)
    # 数据单位加密 21
    encryption = ReportField(start_index=21, end_index=21, order_no=4, encode_fun=None, decode_fun=Common.hex_int)
    # 数据单元长度 22-23
    total_len = ReportField(start_index=22, end_index=23, order_no=5, encode_fun=None, decode_fun=Common.hex_int)

    # 采集时间 25-30
    gather_time = ReportField(start_index=24, end_index=29, order_no=7, encode_fun=None, decode_fun=Common.hex_date_6)
    # 校验码
    check_code = ReportField(order_no=9, encode_fun=None, decode_fun=Common.hex_int, start_fun=Common.check_code_index,
                             end_fun=Common.check_code_index)

    def __init__(self) -> None:
        # 定义初始默认字段
        self.report_time = None
        self.log_time = None
        self.vin_code = None
        self.report_hex_info = None
        self.gather_time = None


# body解析
class BodyMsg:
    # 信号类标志
    msg_type = ReportField(order_no=0, start_index=1, end_index=1, encode_fun=None, decode_fun=Common.hex_int)

    def __init__(self) -> None:
        super().__init__()
        self.msg_type = None


# 整车数据
class BodyCar(BodyMsg):
    # 车辆状态
    car_status = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None, decode_fun=Common.hex_int)
    #  充电状态
    charging_status = ReportField(order_no=2, start_index=3, end_index=3, encode_fun=None, decode_fun=Common.hex_int)
    # 运行模式
    run_model = ReportField(order_no=3, start_index=4, end_index=4, encode_fun=None, decode_fun=Common.hex_int)
    # 车速
    car_speed = ReportField(order_no=4, start_index=5, end_index=6, encode_fun=None, decode_fun=Common.hex_int)
    # 累计里程
    total_mileage = ReportField(order_no=5, start_index=7, end_index=10, encode_fun=None, decode_fun=Common.hex_int)
    # 总电压
    total_voltage = ReportField(order_no=6, start_index=11, end_index=12, encode_fun=None, decode_fun=Common.hex_int)
    # 总电流
    total_current = ReportField(order_no=6, start_index=13, end_index=14, encode_fun=None, decode_fun=Common.hex_int)
    # soc
    soc = ReportField(order_no=7, start_index=15, end_index=15, encode_fun=None, decode_fun=Common.hex_int)
    # DC_DC状态
    dc_status = ReportField(order_no=8, start_index=16, end_index=16, encode_fun=None, decode_fun=Common.hex_int)
    # 挡位
    gears = ReportField(order_no=9, start_index=17, end_index=17, encode_fun=None,
                        decode_fun=lambda bits: bin(int(bits[0], 16))[2:].zfill(8)[4:])
    # 制动力
    braking_force = ReportField(order_no=10, start_index=17, end_index=17, encode_fun=None,
                                decode_fun=lambda bits: bin(int(bits[0], 16))[2:].zfill(8)[2:3])
    # 驱动力
    driving_force = ReportField(order_no=11, start_index=17, end_index=17, encode_fun=None,
                                decode_fun=lambda bits: bin(int(bits[0], 16))[2:].zfill(8)[3:4])
    # 绝缘电阻
    insulation_resistance = ReportField(order_no=12, start_index=18, end_index=19, encode_fun=None,
                                        decode_fun=Common.hex_int)
    # 预留位
    reserved = ReportField(order_no=13, start_index=20, end_index=21, encode_fun=None, decode_fun=Common.hex_int)


# 驱动电机报文
class TBodyDriveMotor(BodyMsg):
    # 驱动电机个数
    reserved_num = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None, decode_fun=Common.hex_int)


# 驱动电机报文
class BodyDriveMotor:
    # 驱动电机序号 1
    drive_no = ReportField(order_no=1, start_index=1, end_index=1, encode_fun=None, decode_fun=Common.hex_int)
    # 驱动电机状态 1
    drive_status = ReportField(order_no=2, start_index=2, end_index=2, encode_fun=None, decode_fun=Common.hex_int)
    # 驱动电机 控制器温度 1
    action_temperature = ReportField(order_no=3, start_index=3, end_index=3, encode_fun=None, decode_fun=Common.hex_int)
    # 驱动电机转速 2
    rotate_speed = ReportField(order_no=4, start_index=4, end_index=5, encode_fun=None, decode_fun=Common.hex_int)
    # 驱动电机转矩 2
    torque = ReportField(order_no=5, start_index=6, end_index=7, encode_fun=None, decode_fun=Common.hex_int)
    # 驱动电机温度 1
    drive_temperature = ReportField(order_no=6, start_index=8, end_index=8, encode_fun=None, decode_fun=Common.hex_int)
    # 控制器输入电压
    action_input_voltage = ReportField(order_no=7, start_index=9, end_index=10, encode_fun=None,
                                       decode_fun=Common.hex_int)
    # 控制器直流母线电流
    action_dc_bus_current = ReportField(order_no=8, start_index=11, end_index=12, encode_fun=None,
                                        decode_fun=Common.hex_int)


# 燃料电池数据
class BodyFuelBattery(BodyMsg):
    # 燃料电池电压 2
    fuel_battery_voltage = ReportField(order_no=2, start_index=2, end_index=3, encode_fun=None,
                                       decode_fun=Common.hex_int)
    # 燃料电池电流 2
    fuel_battery_current = ReportField(order_no=3, start_index=4, end_index=5, encode_fun=None,
                                       decode_fun=Common.hex_int)
    # 燃料消耗率 2
    fuel_consumption = ReportField(order_no=4, start_index=6, end_index=7, encode_fun=None, decode_fun=Common.hex_int)
    # 燃料电池温度探针总数 2
    fuel_battery_t_probe_num = ReportField(order_no=5, start_index=8, end_index=9, encode_fun=None,
                                           decode_fun=Common.hex_int)
    # 探针温度值 N
    temperature_probe_val = ReportField(order_no=6, custom_decode_fun=lambda *args, **kwargs: Common.code_list(
        'fuel_battery_t_probe_num', 1, *args, **kwargs))
    # 氢系统中最高温度 2
    h_system_highest_temperature = ReportField(order_no=7, start_fun=Common.offset_r_1, end_fun=Common.offset_r_2,
                                               decode_fun=Common.hex_int)
    # 氢系统中最高温度 探针代号 1
    h_system_highest_probe_no = ReportField(order_no=8, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                            decode_fun=Common.hex_int)
    # 氢气最高浓度 2
    h_highest_ctr = ReportField(order_no=9, start_fun=Common.offset_r_1, end_fun=Common.offset_r_2,
                                decode_fun=Common.hex_int)
    # 氢气最高浓度 传感器代号 1
    h_highest_ctr_no = ReportField(order_no=10, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                   encode_fun=None, decode_fun=Common.hex_int)

    # 氢气最高压力 2
    h_highest_pressure = ReportField(order_no=11, start_fun=Common.offset_r_1, end_fun=Common.offset_r_2,
                                     encode_fun=None, decode_fun=Common.hex_int)
    # 氢气最高压力传感器代号 1
    h_highest_pressure_no = ReportField(order_no=12, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                        encode_fun=None, decode_fun=Common.hex_int)
    # 高压 dc 状态 1
    hight_pressure_status = ReportField(order_no=13, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                        encode_fun=None, decode_fun=Common.hex_int)


# 车辆位置数据
class BodyCarGps(BodyMsg):
    # 定位状态 1
    gps_status = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None, decode_fun=Common.hex_int)
    # 经度
    lot = ReportField(order_no=2, start_index=3, end_index=6, encode_fun=None, decode_fun=Common.hex_int)
    # 纬度
    lat = ReportField(order_no=3, start_index=7, end_index=10, encode_fun=None, decode_fun=Common.hex_int)


# 发动机部分数据
class BodyEngineData(BodyMsg):
    # 发动机状态 1
    engine_status = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None, decode_fun=Common.hex_int)
    # 曲轴转速 2
    crankshaft_speed = ReportField(order_no=2, start_index=3, end_index=4, encode_fun=None, decode_fun=Common.hex_int)
    # 燃料消耗率
    fuel_consume = ReportField(order_no=3, start_index=4, end_index=5, encode_fun=None, decode_fun=Common.hex_int)


# 极值数据
class BodyExtremeValue(BodyMsg):
    # 最高电压电池子系统号 1
    highest_voltage_subsystem_no = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None,
                                               decode_fun=Common.hex_int)
    # 最高电压电池单体代号 1
    highest_voltage_monomer_no = ReportField(order_no=2, start_index=3, end_index=3, encode_fun=None,
                                             decode_fun=Common.hex_int)
    # 电池单体电压最高值 2
    monomer_voltage_highest_val = ReportField(order_no=3, start_index=4, end_index=5, encode_fun=None,
                                              decode_fun=Common.hex_int)
    # 最低电压电池子系统号 1
    lowest_voltage_subsystem_no = ReportField(order_no=4, start_index=6, end_index=6, encode_fun=None,
                                              decode_fun=Common.hex_int)
    # 最低电压电池单体代号 1
    lowest_voltage_monomer_no = ReportField(order_no=5, start_index=7, end_index=7, encode_fun=None,
                                            decode_fun=Common.hex_int)
    # 电池单体电压最低值 2
    monomer_voltage_lowest_val = ReportField(order_no=6, start_index=8, end_index=9, encode_fun=None,
                                             decode_fun=Common.hex_int)
    # 最高温度子系统号 1
    highest_temperature_subsystem_no = ReportField(order_no=7, start_index=10, end_index=10, encode_fun=None,
                                                   decode_fun=Common.hex_int)
    # 最高温度探针序号 1
    highest_temperature_probe_no = ReportField(order_no=8, start_index=11, end_index=11, encode_fun=None,
                                               decode_fun=Common.hex_int)
    # 最高温度值 1
    highest_temperature_val = ReportField(order_no=9, start_index=12, end_index=12, encode_fun=None,
                                          decode_fun=Common.hex_int)
    # 最低温度子系统号 1
    lowest_temperature_subsystem_no = ReportField(order_no=10, start_index=13, end_index=13, encode_fun=None,
                                                  decode_fun=Common.hex_int)
    # 最低温度探针序号 1
    lowest_temperature_probe_no = ReportField(order_no=11, start_index=14, end_index=14, encode_fun=None,
                                              decode_fun=Common.hex_int)
    # 最低温度值 1
    lowest_temperature_val = ReportField(order_no=12, start_index=15, end_index=15, encode_fun=None,
                                         decode_fun=Common.hex_int)


# 可充电储能装置电压数据格式和定义
class TBodyChargingDeviceVoltage(BodyMsg):
    # 装置数量
    device_num = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None, decode_fun=Common.hex_int)


# 可充电储能装置电压
class BodyChargingDeviceVoltage:
    # 驱动电机序号 1
    charging_no = ReportField(order_no=1, start_index=1, end_index=1, encode_fun=None, decode_fun=Common.hex_int)
    # 电压 2
    voltage = ReportField(order_no=2, start_index=2, end_index=3, encode_fun=None, decode_fun=Common.hex_int)
    # 电流 2
    current = ReportField(order_no=3, start_index=4, end_index=5, encode_fun=None, decode_fun=Common.hex_int)
    # 单体电池总数 2
    battery_num = ReportField(order_no=4, start_index=6, end_index=7, encode_fun=None, decode_fun=Common.hex_int)
    # 本帧起始电池序号 2
    frame_battery_no = ReportField(order_no=5, start_index=8, end_index=9, encode_fun=None, decode_fun=Common.hex_int)
    # 本帧起始电池总数 1
    frame_battery_num = ReportField(order_no=6, start_index=10, end_index=10, encode_fun=None,
                                    decode_fun=Common.hex_int)
    # 单体电池电压 2*m
    monomer_battery_voltage = ReportField(order_no=7, custom_decode_fun=lambda *args, **kwargs: Common.code_list(
        'frame_battery_num', 2, *args, **kwargs))


# 可充电储能装置温度数据格式和定义
class TBodyChargingDeviceTemperature(BodyMsg):
    # 可充能的子系统个数
    temperature_system_num = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None,
                                         decode_fun=Common.hex_int)


# 可充电储能装置温度
class BodyChargingDeviceTemperature:
    # 子系统序号 1
    charging_system_no = ReportField(order_no=1, start_index=1, end_index=1, encode_fun=None, decode_fun=Common.hex_int)
    # 探针个数 2
    probe_num = ReportField(order_no=2, start_index=2, end_index=3, encode_fun=None, decode_fun=Common.hex_int)
    # 探针温度  m
    probe_temperature = ReportField(order_no=3, custom_decode_fun=lambda *args, **kwargs: Common.code_list(
        'probe_num', 1, *args, **kwargs))


# 报警数据
class BodyPoliceData(BodyMsg):
    # 最高报警等级 1
    police_highest_level = ReportField(order_no=1, start_index=2, end_index=2, encode_fun=None,
                                       decode_fun=Common.hex_int)
    # 通用报警标志
    police_general_flag = ReportField(order_no=2, start_index=3, end_index=6, encode_fun=None,
                                      decode_fun=Common.hex_int)
    # 可充电储能装置故障总数
    charging_storage_fault_num = ReportField(order_no=3, start_index=7, end_index=7, encode_fun=None,
                                             decode_fun=Common.hex_int)
    # 可充电储能装置故障代码列表
    charging_storage_fault_code = ReportField(order_no=4,
                                              custom_decode_fun=lambda *args, **kwargs: Common.code_list(
                                                  'charging_storage_fault_num', 4, *args, **kwargs))
    # 驱动电机 故障总数
    drive_fault_num = ReportField(order_no=5, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                  decode_fun=Common.hex_int)
    # 驱动电机 故障代码列表
    drive_fault_code = ReportField(order_no=6, custom_decode_fun=lambda *args, **kwargs: Common.code_list(
        'drive_fault_num', 4, *args, **kwargs))
    # 发动机故障总数
    police_engine_num = ReportField(order_no=7, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                    decode_fun=Common.hex_int)
    # 发动机故障列表
    police_engine_code = ReportField(order_no=8, custom_decode_fun=lambda *args, **kwargs: Common.code_list(
        'police_engine_num', 4, *args, **kwargs))

    # 其他故障总数
    police_other_num = ReportField(order_no=9, start_fun=Common.offset_r_1, end_fun=Common.offset_r_1,
                                   decode_fun=Common.hex_int)
    # 其他故障代码列表
    police_other_code = ReportField(order_no=10, custom_decode_fun=lambda *args, **kwargs: Common.code_list(
        'police_other_num', 4, *args, **kwargs))


# 字段解码
def field_decode(b_arr: list[str], offset=0, r_p_dict={}, rs=None, class_type=None):
    attr_list = list(
        filter(lambda att: isinstance(att.object, ReportField), inspect.classify_class_attrs(class_type)))
    attr_list.sort(key=lambda att: att.object.order_no)

    [rs.__setattr__(attr.name,
                    attr.object.decode(b_arr, offset=offset, fieldName=attr.name, r_p_dict=r_p_dict, heard=rs)[2])
     for attr in attr_list]
    pass


def decode(log_str: str, vin_code: str = None):
    rs = RealtimeSignal()
    rp_type = re.sub(r'业务类型|\[|\]', '', re.search(r'业务类型\[\w*\]', log_str).group())
    if rp_type != 'REALTIME_SIGNAL':
        return None
    rs.vin_code = re.sub(r'唯一码|\[|\]', '', re.search(r'唯一码\[[\w]{17}\]', log_str).group())
    if vin_code is not None and vin_code != rs.vin_code:
        return None
    # 1. 先将每行数据进行正则匹配
    rs.report_time = re.sub(r'\[|\]', '',
                            re.search(r'\[[0-9]{4}-[0-9]{2}-[0-9]{2}[\s]{1}[0-9]{2}:[0-9]{2}:[0-9]{2}\]',
                                      log_str).group())
    rs.log_time = re.search(r'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} ', log_str).group()

    # 2. 再将最终报文时间解析
    rs.report_hex_info = Common.hex_str_split(
        re.sub(r'报文|\[|\]', '', re.search(r'报文\[[0-9A-Fa-f]*\]', log_str).group()))
    if rs.report_hex_info is None:
        return None
    b_arr = rs.report_hex_info.split(' ')
    r_p_dict = {}
    # 报文头得解析
    field_decode(b_arr, 0, r_p_dict=r_p_dict, rs=rs, class_type=RealtimeSignal)
    offset = list(r_p_dict.items())[len(r_p_dict.items()) - 2][1][1]

    map_field_list = list()
    rs_dict = rs.__dict__

    def _batch(re_dict, num, batch_class):
        if num == 0:
            map_field_list.append(re_dict)
        else:
            for index in range(num):
                offset = list(r_p_dict.items())[len(r_p_dict.items()) - 1][1][1]
                rec_obj = batch_class()
                field_decode(b_arr, offset=offset, r_p_dict=r_p_dict, rs=rec_obj, class_type=batch_class)
                rec_dict = rec_obj.__dict__
                rec_dict.update(re_dict)
                map_field_list.append(rec_dict)
        pass

    def normal(re_obj, re_class):
        field_decode(b_arr, offset=offset, r_p_dict=r_p_dict, rs=re_obj, class_type=re_class)
        re_dict = re_obj.__dict__
        re_dict.update(rs.__dict__)
        map_field_list.append(re_dict)
        pass

    # 数据单元解析
    while offset != len(b_arr) - 2:
        msg_type = b_arr[offset + 1:offset + 2][0]
        if msg_type == '01':  # 整车数据
            re_obj = BodyCar()
            normal(re_obj, BodyCar)
        elif msg_type == '02':  # 驱动电机数据
            re_obj = TBodyDriveMotor()
            field_decode(b_arr, offset=offset, r_p_dict=r_p_dict, rs=re_obj, class_type=TBodyDriveMotor)
            re_dict = re_obj.__dict__
            re_dict.update(rs.__dict__)
            _batch(re_dict, re_obj.reserved_num, BodyDriveMotor)
        elif msg_type == '03':  # 燃料电池数据
            re_obj = BodyFuelBattery()
            normal(re_obj, BodyFuelBattery)
        elif msg_type == '04':  # 发动机数据
            re_obj = BodyEngineData()
            normal(re_obj, BodyEngineData)
        elif msg_type == '05':  # 车辆位置数据
            re_obj = BodyCarGps()
            normal(re_obj, BodyCarGps)
        elif msg_type == '06':  # 极值数据
            re_obj = BodyExtremeValue()
            normal(re_obj, BodyExtremeValue)
        elif msg_type == '07':  # 报警数据
            re_obj = BodyPoliceData()
            normal(re_obj, BodyPoliceData)
        elif msg_type == '08':  # 可充电储能装置电压数据
            re_obj = TBodyChargingDeviceVoltage()
            field_decode(b_arr, offset=offset, r_p_dict=r_p_dict, rs=re_obj, class_type=TBodyChargingDeviceVoltage)
            re_dict = re_obj.__dict__
            re_dict.update(rs.__dict__)
            _batch(re_dict, re_obj.device_num, BodyChargingDeviceVoltage)
        elif msg_type == '09':  # 可充电储能装置温度数据
            re_obj = TBodyChargingDeviceTemperature()
            field_decode(b_arr, offset=offset, r_p_dict=r_p_dict, rs=re_obj, class_type=TBodyChargingDeviceTemperature)
            re_dict = re_obj.__dict__
            re_dict.update(rs.__dict__)
            _batch(re_dict, re_obj.temperature_system_num, BodyChargingDeviceTemperature)
        else:
            rs_dict['offset'] = offset
            break
        offset = list(r_p_dict.items())[len(r_p_dict.items()) - 1][1][1]
    return rs_dict, map_field_list


if __name__ == '__main__':
    # attrList =
    # attrList
    # print(attrList)
    # print([(attr.kind == 'data') for attr in inspect.classify_class_attrs(RealtimeSignal)])
    # print([i for i in dir(RealtimeSignal) if inspect.isbuiltin(getattr(RealtimeSignal, i))])
    log_str = '2022-03-08 00:00:01.152 - INFO  c.z.i.c.a.newrvm.log.MessageLogUtil - 报文时间[2022-03-07 23:59:59],发送报文 业务类型[REALTIME_SIGNAL],唯一码[LSJE36097MS144796],报文[232302FE4C534A4533363039374D53313434373936010159160307173B3B010103010164000050DC10A428944E012E1FFF0E00020201014859C44FE24410AE28780202434E204E1B4210AE270605000738BC3201DD74FE0601090F72014A0F5801053D010B3B0700000000000100000000010000000001000000000008010110A42894006C00016C0F710F6C0F630F6F0F640F6E0F630F6D0F720F6B0F640F670F6A0F660F690F640F6C0F680F590F6A0F660F6A0F630F680F640F690F650F6B0F660F5D0F590F680F640F5E0F5A0F6A0F6C0F650F5E0F660F6B0F650F690F650F660F670F690F670F690F650F670F620F690F650F650F5B0F670F680F650F680F650F6A0F670F6A0F5E0F6A0F650F690F630F5D0F650F6B0F670F580F5F0F640F630F600F6A0F600F620F680F6F0F6F0F600F6B0F6D0F6D0F6B0F610F660F660F670F6A0F660F660F650F630F5A0F5A0F5C0F600F590F590F590F5E0F5A0F5A090101000C3C3C3C3C3D3C3C3C3D3C3B3B04]'
    # realtime = RealtimeSignal()
    # realtime.decode(regx)
    # print(realtime.gather_time)
    # print(bin(31)[2:])
    # print(decode(log_str)[1])
    print(db.insert_dict('report_info', decode(log_str)[0]))
    pass
